﻿/************************************************************************
*  Copyright @   All rights reserved.
*  GUID: 3fdf49b8-39db-4203-8516-461e8ba95416
*  计算机用户域： XIANGLIUBO-PC
*  计算机用户名： WuHao
*  创建者： 向柳波
*  创建时间： 2015-02-12 04:29:54
*  创建说明： 
*  ---------------------------------------------------------------------
*  更新者： 
*  更新时间：
*  更新说明： 
************************************************************************/

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using CommonHelp;
using Core.Unity;
using Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Services;
using ViewModels;

namespace Commands {
    /// <summary>
    /// PM2.5
    /// </summary>
    public class QueryPM25Command : CommandBase {
        private IXContainer _hook;
        private IDisplayTable _IDisplayTable;

        public override void OnCreate(object hook) {
            base.OnCreate(hook);
            _hook = hook as IXContainer;

            _IDisplayTable = _hook.Resolve<IDisplayTable>();
        }

        public override void OnClick(object parameter) {
            base.OnClick(parameter);
            //HttpHelper http = new HttpHelper("http://www.pm25.in/api/querys/all_cities.json?token=6peWxJZPssxa6yo9D3Q4");
            //http.GetAsync(AfterGetData);

            string rst = FileHelper.ReadFile(@"E:\辰安\meteorologicaldatacapturetool\文档 原始\pm25 样例数据\所有城市详细数据.json");
            AfterGetData(rst);

            this.IsEnabled = false;

            //_hook.Resolve<WebViewModel>().Url = "http://typhoon.weather.com.cn/";
        }

        private void AfterGetData(string responseStr) {
            //try {
            //    List<PM25Info> infos = JsonConvert.DeserializeObject<List<PM25Info>>(responseStr);
            //    _IDisplayTable.DisplayData = infos.ToArray();
            //    _IDisplayTable.AddRowVisitor = new AddPM25Info(_hook.Resolve<DbHelp.DbHelper>());
            //    _hook.Resolve<ITextHint>().AddText(DateTime.Now.ToString() + " 获取到 " + infos.Count.ToString() + " 条 PM2.5 数据。");
            //}
            //catch (Exception ex) {
            //    CommonHelp.LogHelper.Error(ex);
            //}
            //finally {
            //    this.IsEnabled = true;
            //}
        } 
    }
}
